/**
 *
 */
package com.aulac.commons.license.server;

import java.util.prefs.Preferences;

import de.schlichtherle.license.CipherParam;
import de.schlichtherle.license.KeyStoreParam;
import de.schlichtherle.license.LicenseParam;

/**
 * @author Ngo Thanh Loi
 *
 */
public final class AulacLicenseParam implements LicenseParam {
	// For application name, sample CRM,CMS
	private String appName;
	private KeyStoreParam privateKeyStoreParam;
	private CipherParam cipherParam;
	private Preferences preferences;

	/**
	 * @param application
	 * @param privateKeyStoreParam
	 * @param cipherParam
	 * @param preferences
	 * @throws NullParameterExecption
	 */
	public AulacLicenseParam(String application,
			KeyStoreParam inputKeyStoreParam, CipherParam inputCipherParam,
			Preferences inputPreferences) throws NullParameterExecption {
		if (application == null || inputCipherParam == null
				|| inputKeyStoreParam == null) {
			throw new NullParameterExecption(
					"The parameter application/cipherParam/KeyStoreParam can't set to NULL value");
		}

		this.appName = application;
		this.privateKeyStoreParam = inputKeyStoreParam;
		this.cipherParam = inputCipherParam;
		this.preferences = inputPreferences;
	}

	/**
	 * @param application
	 * @param keyStoreParam
	 * @param cipherParam
	 */
	public AulacLicenseParam(String application,
			KeyStoreParam inputKeyStoreParam, CipherParam inputCipherParam)
			throws NullParameterExecption {
		if (application == null || inputCipherParam == null
				|| inputKeyStoreParam == null) {
			throw new NullParameterExecption(
					"The parameter application/cipherParam/KeyStoreParam can't set to NULL value");
		}
		this.appName = application;
		this.privateKeyStoreParam = inputKeyStoreParam;
		this.cipherParam = inputCipherParam;
	}

	public String getSubject() {
		return appName;
	}

	public Preferences getPreferences() {
		// TODO why is this needed for the app that creates the license?
		// return Preferences.userNodeForPackage(LicenseServer.class);
		return preferences;
	}

	public KeyStoreParam getKeyStoreParam() {
		return privateKeyStoreParam;
	}

	public CipherParam getCipherParam() {
		return cipherParam;
	}

	/**
	 * @param application
	 *            the application to set
	 */
	public final void setSubject(String application) {
		if (application == null) {
			throw new NullParameterExecption(
					"The parameter application can't set to NULL value");
		}
		this.appName = application;
	}

	/**
	 * @param keyStoreParam
	 *            the keyStoreParam to set
	 */
	public final void setKeyStoreParam(KeyStoreParam keyStoreParam) {
		if (privateKeyStoreParam == null) {
			throw new NullParameterExecption(
					"The parameter privateKeyStoreParam can't set to NULL value");
		}
		this.privateKeyStoreParam = keyStoreParam;
	}

	/**
	 * @param cipherParam
	 *            the cipherParam to set
	 */
	public final void setCipherParam(CipherParam cipherParam) {
		if (cipherParam == null) {
			throw new NullParameterExecption(
					"The parameter cipherParam can't set to NULL value");
		}
		this.cipherParam = cipherParam;
	}

	/**
	 * @param preferences
	 *            the preferences to set
	 */
	public final void setPreferences(Preferences preferences) {
		this.preferences = preferences;
	}
}
